package threading;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-09-20
 * Time: 11:35
 *///标准库实现阻塞队列
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<Integer>  blockingQueue=new LinkedBlockingQueue<>(100);
      //带有阻塞功能的入队列
        blockingQueue.put(1);
        blockingQueue.put(2);
        blockingQueue.put(3);
        blockingQueue.put(4);


        //也带有阻塞的出队列
        Integer  ret=blockingQueue.take();
        System.out.println(ret);
        ret=blockingQueue.take();
        System.out.println(ret);
        ret=blockingQueue.take();
        System.out.println(ret);
        ret=blockingQueue.take();
        System.out.println(ret);


        //阻塞队列没有提供带有阻塞功能取队首元素的功能

    }
}
